} else if let Some(path) = args.value_of_path("path", config) {
SourceId::for_path(&path)?
} else if krates.is_empty() {
- SourceId::for_path(config.cwd())?
+ SourceId::from_cwd(config.cwd())?
} else {
SourceId::crates_io(config)?
};
precise: Option<String>,
/// Name of the registry source for alternative registries
name: Option<String>,
+ from_cwd: bool,
}
-/// The possible kinds of code source. Along with a URL, this fully defines the
+/// The possible kinds of code source. Along with SourceIdInner this fully defines the
/// source
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
enum Kind {
url,
precise: None,
name: None,
+ from_cwd: false,
}),
};
Ok(source_id)
SourceId::new(Kind::Directory, url)
}
+ pub fn from_cwd(path: &Path) -> CargoResult<SourceId> {
+ let url = path.to_url()?;
+ Ok(SourceId {
+ inner: Arc::new(SourceIdInner {
+ kind: Kind::Path,
+ canonical_url: git::canonicalize_url(&url)?,
+ url,
+ precise: None,
+ name: None,
+ from_cwd: true,
+ }),
+ })
+ }
+
/// Returns the `SourceId` corresponding to the main repository.
///
/// This is the main cargo registry by default, but it can be overridden in
url,
precise: None,
name: Some(key.to_string()),
+ from_cwd: false,
}),
})
}
}
}
+ /// Is this source from the current working directory
+ pub fn is_from_cwd(&self) -> bool {
+ self.inner.from_cwd
+ }
+
/// Creates an implementation of `Source` corresponding to this ID.
pub fn load<'a>(&self, config: &'a Config) -> CargoResult<Box<super::Source + 'a>> {
trace!("loading SourceId; {}", self);
use tempfile::Builder as TempFileBuilder;
use toml;
-use core::{Dependency, Package, PackageIdSpec, Source, SourceId};
+use core::{Dependency, Edition, Package, PackageIdSpec, Source, SourceId};
use core::{PackageId, Workspace};
use ops::{self, CompileFilter, DefaultExecutor};
use sources::{GitSource, PathSource, SourceConfigMap};
};
let pkg = ws.current()?;
+ if source_id.is_from_cwd() {
+ match pkg.manifest().edition() {
+ Edition::Edition2015 => (),
+ Edition::Edition2018 => {
+ config.shell().warn("To build the current package use 'cargo build', to install the current package run `cargo install --path .`")?;
+ },
+ }
+ };
+
config.shell().status("Installing", pkg)?;
// Preflight checks to check up front whether we'll overwrite something.
use std::io::prelude::*;
use cargo::util::ProcessBuilder;
+use cargotest::ChannelChanger;
use cargotest::install::{cargo_home, has_installed_exe};
use cargotest::support::git;
use cargotest::support::paths;
assert_that(cargo_home(), has_installed_exe("foo"));
}
+#[test]
+fn installs_from_cwd_with_2018_warnings() {
+ if !cargotest::is_nightly() {
+ // Stable rust won't have the edition option. Remove this once it
+ // is stabilized.
+ return;
+ }
+ let p = project("foo")
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
+ "#,
+ )
+ .file("src/main.rs", "fn main() {}")
+ .build();
+
+ assert_that(
+ cargo_process("install").cwd(p.root()).masquerade_as_nightly_cargo(),
+ execs().with_status(0).with_stderr_contains(
+ "\
+warning: To build the current package use 'cargo build', to install the current package run `cargo install --path .`
+",
+ ),
+ );
+ assert_that(cargo_home(), has_installed_exe("foo"));
+}
+
#[test]
fn do_not_rebuilds_on_local_install() {
let p = project("foo")